home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / comm / term / term41source.lha / Extras / Source / term-Source.lha / SoundPanel.c < prev    next >
C/C++ Source or Header  |  1994-07-30  |  10KB  |  411 lines

  1. /*
  2. **    SoundPanel.c
  3. **
  4. **    Editing panel for sound configuration
  5. **
  6. **    Copyright © 1990-1994 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12. enum    {    GAD_BELL=1,GAD_CONNECT,GAD_DISCONNECT,GAD_GOOD_TRANSFER,
  13.         GAD_BAD_TRANSFER,GAD_RING,GAD_VOICE,GAD_PRELOAD,GAD_VOLUME,
  14.         GAD_USE,GAD_LOAD,GAD_SAVE,GAD_CANCEL
  15.     };
  16.  
  17. BYTE __regargs
  18. SoundPanel(struct SoundConfig *Config)
  19. {
  20.     struct LayoutHandle *Handle;
  21.  
  22.     STATIC struct SoundConfig __far BackupConfig;
  23.  
  24.     CopyMem(Config,&BackupConfig,sizeof(struct SoundConfig));
  25.  
  26.     if(Handle = LT_CreateHandleTags(Window -> WScreen,
  27.         LH_LocaleHook,    &LocaleHook,
  28.     TAG_DONE))
  29.     {
  30.         struct Window *PanelWindow;
  31.  
  32.         LT_New(Handle,
  33.             LA_Type,    VERTICAL_KIND,
  34.         TAG_DONE);
  35.         {
  36.             LT_New(Handle,
  37.                 LA_Type,    VERTICAL_KIND,
  38.                 LA_LabelID,    MSG_V36_0182,
  39.             TAG_DONE);
  40.             {
  41.                 LT_New(Handle,
  42.                     LA_Type,    VERTICAL_KIND,
  43.                 TAG_DONE);
  44.                 {
  45.                     LT_New(Handle,
  46.                         LA_Type,    STRING_KIND,
  47.                         LA_LabelID,    MSG_SOUNDPANEL_BELL_GAD,
  48.                         LA_STRPTR,    Config -> BellFile,
  49.                         LA_Chars,    30,
  50.                         LA_ID,        GAD_BELL,
  51.                         LAST_Picker,    TRUE,
  52.                         GTST_MaxChars,    MAX_FILENAME_LENGTH - 1,
  53.                     TAG_DONE);
  54.  
  55.                     LT_New(Handle,
  56.                         LA_Type,    STRING_KIND,
  57.                         LA_LabelID,    MSG_SOUNDPANEL_CONNECT_GAD,
  58.                         LA_STRPTR,    Config -> ConnectFile,
  59.                         LA_ID,        GAD_CONNECT,
  60.                         LAST_Picker,    TRUE,
  61.                         GTST_MaxChars,    MAX_FILENAME_LENGTH - 1,
  62.                     TAG_DONE);
  63.  
  64.                     LT_New(Handle,
  65.                         LA_Type,    STRING_KIND,
  66.                         LA_LabelID,    MSG_SOUNDPANEL_DISCONNECT_GAD,
  67.                         LA_STRPTR,    Config -> DisconnectFile,
  68.                         LA_ID,        GAD_DISCONNECT,
  69.                         LAST_Picker,    TRUE,
  70.                         GTST_MaxChars,    MAX_FILENAME_LENGTH - 1,
  71.                     TAG_DONE);
  72.  
  73.                     LT_New(Handle,
  74.                         LA_Type,    STRING_KIND,
  75.                         LA_LabelID,    MSG_SOUNDPANEL_GOOD_TRANSFER_GAD,
  76.                         LA_STRPTR,    Config -> GoodTransferFile,
  77.                         LA_ID,        GAD_GOOD_TRANSFER,
  78.                         LAST_Picker,    TRUE,
  79.                         GTST_MaxChars,    MAX_FILENAME_LENGTH - 1,
  80.                     TAG_DONE);
  81.  
  82.                     LT_New(Handle,
  83.                         LA_Type,    STRING_KIND,
  84.                         LA_LabelID,    MSG_SOUNDPANEL_BAD_TRANSFER_GAD,
  85.                         LA_STRPTR,    Config -> BadTransferFile,
  86.                         LA_ID,        GAD_BAD_TRANSFER,
  87.                         LAST_Picker,    TRUE,
  88.                         GTST_MaxChars,    MAX_FILENAME_LENGTH - 1,
  89.                     TAG_DONE);
  90.  
  91.                     LT_New(Handle,
  92.                         LA_Type,    STRING_KIND,
  93.                         LA_LabelID,    MSG_SOUNDPANEL_RING_GAD,
  94.                         LA_STRPTR,    Config -> RingFile,
  95.                         LA_ID,        GAD_RING,
  96.                         LAST_Picker,    TRUE,
  97.                         GTST_MaxChars,    MAX_FILENAME_LENGTH - 1,
  98.                     TAG_DONE);
  99.  
  100.                     LT_New(Handle,
  101.                         LA_Type,    STRING_KIND,
  102.                         LA_LabelID,    MSG_SOUNDPANEL_VOICE_GAD,
  103.                         LA_STRPTR,    Config -> VoiceFile,
  104.                         LA_ID,        GAD_VOICE,
  105.                         LAST_Picker,    TRUE,
  106.                         GTST_MaxChars,    MAX_FILENAME_LENGTH - 1,
  107.                     TAG_DONE);
  108.  
  109.                     LT_EndGroup(Handle);
  110.                 }
  111.  
  112.                 LT_New(Handle,
  113.                     LA_Type,    XBAR_KIND,
  114.                 TAG_DONE);
  115.  
  116.                 LT_New(Handle,
  117.                     LA_Type,    VERTICAL_KIND,
  118.                 TAG_DONE);
  119.                 {
  120.                     LT_New(Handle,
  121.                         LA_Type,        SLIDER_KIND,
  122.                         LA_LabelID,        MSG_SOUNDPANEL_VOLUME_GAD,
  123.                         LA_BYTE,        &Config -> Volume,
  124.                         LA_ID,            GAD_VOLUME,
  125.                         LA_Chars,        10,
  126.                         GTSL_Min,        0,
  127.                         GTSL_Max,        100,
  128.                         GTSL_LevelFormat,    "%ld%%",
  129.                     TAG_DONE);
  130.  
  131.                     LT_New(Handle,
  132.                         LA_Type,    CHECKBOX_KIND,
  133.                         LA_LabelID,    MSG_SOUNDPANEL_PRELOAD_GAD,
  134.                         LA_BYTE,    &Config -> Preload,
  135.                         LA_ID,        GAD_PRELOAD,
  136.                     TAG_DONE);
  137.  
  138.                     LT_EndGroup(Handle);
  139.                 }
  140.  
  141.                 LT_EndGroup(Handle);
  142.             }
  143.  
  144.             LT_New(Handle,
  145.                 LA_Type,VERTICAL_KIND,
  146.             TAG_DONE);
  147.             {
  148.                 LT_New(Handle,
  149.                     LA_Type,    XBAR_KIND,
  150.                     LAXB_FullSize,    TRUE,
  151.                 TAG_DONE);
  152.  
  153.                 LT_EndGroup(Handle);
  154.             }
  155.  
  156.             LT_New(Handle,LA_Type,HORIZONTAL_KIND,
  157.                 LAGR_SameSize,    TRUE,
  158.                 LAGR_Spread,    TRUE,
  159.             TAG_DONE);
  160.             {
  161.                 LT_New(Handle,
  162.                     LA_Type,    BUTTON_KIND,
  163.                     LA_LabelID,    MSG_GLOBAL_USE_GAD,
  164.                     LA_ID,        GAD_USE,
  165.                     LABT_ReturnKey,    TRUE,
  166.                     LABT_ExtraFat,    TRUE,
  167.                 TAG_DONE);
  168.  
  169.                 LT_New(Handle,
  170.                     LA_Type,    BUTTON_KIND,
  171.                     LA_LabelID,    MSG_GLOBAL_LOAD_GAD,
  172.                     LA_ID,        GAD_LOAD,
  173.                     LABT_ExtraFat,    TRUE,
  174.                 TAG_DONE);
  175.  
  176.                 LT_New(Handle,
  177.                     LA_Type,    BUTTON_KIND,
  178.                     LA_LabelID,    MSG_GLOBAL_SAVE_GAD,
  179.                     LA_ID,        GAD_SAVE,
  180.                     LABT_ExtraFat,    TRUE,
  181.                 TAG_DONE);
  182.  
  183.                 LT_New(Handle,
  184.                     LA_Type,    BUTTON_KIND,
  185.                     LA_LabelID,    MSG_GLOBAL_CANCEL_GAD,
  186.                     LA_ID,        GAD_CANCEL,
  187.                     LABT_EscKey,    TRUE,
  188.                     LABT_ExtraFat,    TRUE,
  189.                 TAG_DONE);
  190.  
  191.                 LT_EndGroup(Handle);
  192.             }
  193.  
  194.             LT_EndGroup(Handle);
  195.         }
  196.  
  197.         if(PanelWindow = LT_Layout(Handle,LocaleString(MSG_SOUNDPANEL_SOUND_PREFERENCES_TXT),NULL,0,0,IDCMP_CLOSEWINDOW,0,
  198.             LAWN_HelpHook,        &GuideHook,
  199.             LAWN_Parent,        Window,
  200.             WA_DepthGadget,        TRUE,
  201.             WA_CloseGadget,        TRUE,
  202.             WA_DragBar,        TRUE,
  203.             WA_RMBTrap,        TRUE,
  204.             WA_Activate,        TRUE,
  205.         TAG_DONE))
  206.         {
  207.             struct IntuiMessage    *Message;
  208.             BOOLEAN             Done = FALSE;
  209.             ULONG             MsgClass,
  210.                          MsgQualifier;
  211.             UWORD             MsgCode;
  212.             struct Gadget        *MsgGadget;
  213.             STRPTR             DummyChar;
  214.             UBYTE             DummyBuffer[MAX_FILENAME_LENGTH];
  215.             struct FileRequester    *FileRequest;
  216.  
  217.             GuideContext(CONTEXT_SOUND);
  218.  
  219.             PushWindow(PanelWindow);
  220.  
  221.             do
  222.             {
  223.                 if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
  224.                 {
  225.                     CopyMem(&BackupConfig,Config,sizeof(struct SoundConfig));
  226.  
  227.                     break;
  228.                 }
  229.  
  230.                 while(Message = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort))
  231.                 {
  232.                     MsgClass    = Message -> Class;
  233.                     MsgQualifier    = Message -> Qualifier;
  234.                     MsgCode        = Message -> Code;
  235.                     MsgGadget    = (struct Gadget *)Message -> IAddress;
  236.  
  237.                     GT_ReplyIMsg(Message);
  238.  
  239.                     LT_HandleInput(Handle,MsgQualifier,&MsgClass,&MsgCode,&MsgGadget);
  240.  
  241.                     if(MsgClass == IDCMP_CLOSEWINDOW)
  242.                     {
  243.                         CopyMem(&BackupConfig,Config,sizeof(struct SoundConfig));
  244.  
  245.                         Done = TRUE;
  246.                     }
  247.  
  248.                     if(MsgClass == IDCMP_GADGETUP)
  249.                     {
  250.                         switch(MsgGadget -> GadgetID)
  251.                         {
  252.                             case GAD_USE:
  253.  
  254.                                 SoundChanged = memcmp(&BackupConfig,Config,sizeof(struct SoundConfig));
  255.  
  256.                                 Done = TRUE;
  257.                                 break;
  258.  
  259.                             case GAD_CANCEL:
  260.  
  261.                                 CopyMem(&BackupConfig,Config,sizeof(struct SoundConfig));
  262.  
  263.                                 Done = TRUE;
  264.                                 break;
  265.  
  266.                             case GAD_LOAD:
  267.  
  268.                                 SplitFileName(LastSound,&DummyChar,DummyBuffer);
  269.  
  270.                                 LT_LockWindow(PanelWindow);
  271.  
  272.                                 if(FileRequest = GetFile(PanelWindow,LocaleString(MSG_SOUNDPANEL_LOAD_SOUNDS_TXT),DummyBuffer,FilePart(LastSound),DummyBuffer,"#?.prefs",FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_LOAD_TXT),TRUE))
  273.                                 {
  274.                                     if(!ReadIFFData(DummyBuffer,Config,sizeof(struct SoundConfig),ID_SOUN))
  275.                                         ShowError(PanelWindow,ERR_LOAD_ERROR,IoErr(),DummyBuffer);
  276.                                     else
  277.                                     {
  278.                                         SoundChanged = FALSE;
  279.  
  280.                                         strcpy(LastSound,DummyBuffer);
  281.  
  282.                                         LT_SetAttributes(Handle,GAD_BELL,
  283.                                             GTST_String,Config -> BellFile,
  284.                                         TAG_DONE);
  285.  
  286.                                         LT_SetAttributes(Handle,GAD_CONNECT,
  287.                                             GTST_String,Config -> ConnectFile,
  288.                                         TAG_DONE);
  289.  
  290.                                         LT_SetAttributes(Handle,GAD_DISCONNECT,
  291.                                             GTST_String,Config -> DisconnectFile,
  292.                                         TAG_DONE);
  293.  
  294.                                         LT_SetAttributes(Handle,GAD_GOOD_TRANSFER,
  295.                                             GTST_String,Config -> GoodTransferFile,
  296.                                         TAG_DONE);
  297.  
  298.                                         LT_SetAttributes(Handle,GAD_BAD_TRANSFER,
  299.                                             GTST_String,Config -> BadTransferFile,
  300.                                         TAG_DONE);
  301.  
  302.                                         LT_SetAttributes(Handle,GAD_RING,
  303.                                             GTST_String,Config -> RingFile,
  304.                                         TAG_DONE);
  305.  
  306.                                         LT_SetAttributes(Handle,GAD_VOICE,
  307.                                             GTST_String,Config -> VoiceFile,
  308.                                         TAG_DONE);
  309.  
  310.                                         LT_SetAttributes(Handle,GAD_PRELOAD,
  311.                                             GTCB_Checked,Config -> Preload,
  312.                                         TAG_DONE);
  313.  
  314.                                         LT_SetAttributes(Handle,GAD_VOLUME,
  315.                                             GTSL_Level,Config -> Volume,
  316.                                         TAG_DONE);
  317.                                     }
  318.  
  319.                                     FreeAslRequest(FileRequest);
  320.                                 }
  321.  
  322.                                 LT_UnlockWindow(PanelWindow);
  323.  
  324.                                 break;
  325.  
  326.                             case GAD_SAVE:
  327.  
  328.                                 SplitFileName(LastSound,&DummyChar,DummyBuffer);
  329.  
  330.                                 LT_LockWindow(PanelWindow);
  331.  
  332.                                 if(FileRequest = GetFile(PanelWindow,LocaleString(MSG_SOUNDPANEL_SAVE_SOUNDS_TXT),DummyBuffer,FilePart(LastSound),DummyBuffer,"#?.prefs",TRUE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SAVE_TXT),TRUE))
  333.                                 {
  334.                                     if(!WriteIFFData(DummyBuffer,Config,sizeof(struct SoundConfig),ID_SOUN))
  335.                                         ShowError(PanelWindow,ERR_SAVE_ERROR,IoErr(),DummyBuffer);
  336.                                     else
  337.                                     {
  338.                                         strcpy(LastSound,DummyBuffer);
  339.  
  340.                                         SoundChanged = FALSE;
  341.                                     }
  342.  
  343.                                     FreeAslRequest(FileRequest);
  344.                                 }
  345.  
  346.                                 LT_UnlockWindow(PanelWindow);
  347.  
  348.                                 break;
  349.  
  350.                             default:
  351.  
  352.                                 if(MsgGadget -> GadgetID >= GAD_BELL && MsgGadget -> GadgetID <= GAD_VOICE)
  353.                                 {
  354.                                     if(MsgCode == '\r' && Config -> Volume)
  355.                                     {
  356.                                         STRPTR Name;
  357.  
  358.                                         LT_LockWindow(PanelWindow);
  359.  
  360.                                         Name = (STRPTR)LT_GetAttributes(Handle,MsgGadget -> GadgetID,TAG_DONE);
  361.  
  362.                                         if(Name[0])
  363.                                         {
  364.                                             struct SoundInfo *SoundInfo;
  365.  
  366.                                             if(SoundInfo = LoadSound(Name,FALSE))
  367.                                             {
  368.                                                 PlaySound(SoundInfo);
  369.  
  370.                                                 FreeSound(SoundInfo);
  371.                                             }
  372.                                         }
  373.  
  374.                                         LT_UnlockWindow(PanelWindow);
  375.                                     }
  376.                                 }
  377.  
  378.                                 break;
  379.                         }
  380.                     }
  381.  
  382.                     if(MsgClass == IDCMP_IDCMPUPDATE && MsgGadget -> GadgetID >= GAD_BELL && MsgGadget -> GadgetID <= GAD_VOICE)
  383.                     {
  384.                         SplitFileName((STRPTR)LT_GetAttributes(Handle,MsgGadget -> GadgetID,TAG_DONE),&DummyChar,DummyBuffer);
  385.  
  386.                         LT_LockWindow(PanelWindow);
  387.  
  388.                         if(FileRequest = GetFile(PanelWindow,LocaleString(MSG_SOUNDPANEL_SELECT_BELL_TXT + MsgGadget -> GadgetID - GAD_BELL),DummyBuffer,DummyChar,DummyBuffer,NULL,FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SELECT_TXT),TRUE))
  389.                         {
  390.                             LT_SetAttributes(Handle,MsgGadget -> GadgetID,
  391.                                 GTST_String,DummyBuffer,
  392.                             TAG_DONE);
  393.  
  394.                             FreeAslRequest(FileRequest);
  395.                         }
  396.  
  397.                         LT_UnlockWindow(PanelWindow);
  398.                     }
  399.                 }
  400.             }
  401.             while(!Done);
  402.  
  403.             PopWindow();
  404.         }
  405.  
  406.         LT_DeleteHandle(Handle);
  407.     }
  408.  
  409.     return((BYTE)memcmp(&BackupConfig,Config,sizeof(struct SoundConfig)));
  410. }
  411.